<template>
	<div>
		<a-form class="ant-advanced-search-form home-form" :form="form" @submit="handleSearch">
			<a-row :gutter="24">
				<a-col :span="8">
					<a-form-item label="名称">
						<a-input placeholder="请输入名称搜索" autocomplete="off" class="field-right" v-decorator="[`key`]" />
					</a-form-item>
				</a-col>
				<a-col :span="8" style="margin-top: 4px;">
					<a-button-group class="btngroupoption">
						<a-button type="primary" @click="handleSearch">搜索</a-button>
						<a-button @click="handleReset">重置</a-button>
						<a-button type="primary" @click="seeList({}, 1)">新增</a-button>
					</a-button-group>
				</a-col>
			</a-row>
		</a-form>
		<div class="table">
			<el-table :data="data" v-loading="loading" border highlight-current-row style="width: 100%;">
				<el-table-column type="index" label="序号" width="60"></el-table-column>
				<el-table-column prop="Name" label="名称" min-width="100"></el-table-column>
				<el-table-column prop="TypeName" label="类型" min-width="60"></el-table-column>
				<el-table-column prop="Score" label="学分" min-width="60"></el-table-column>
				<el-table-column prop="SemesterName" label="所属学期" min-width="100"></el-table-column>
				<el-table-column prop="Name" label="团队申报时间" min-width="160">
					<template slot-scope="scope">
						<div>开始：{{ scope.row.StartTime }}</div>
						<div>结束：{{ scope.row.EndTime }}</div>
					</template>
				</el-table-column>
				<el-table-column prop="Name" label="结项时间" min-width="160">
					<template slot-scope="scope">
						<div>开始：{{ scope.row.CloseStartTime }}</div>
						<div>结束：{{ scope.row.CloseEndTime }}</div>
					</template>
				</el-table-column>
				<el-table-column prop="Name" label="发放学分时间" min-width="160">
					<template slot-scope="scope">
						<div>开始：{{ scope.row.SendScoreStartTime }}</div>
						<div>结束：{{ scope.row.SendScoreEndTime }}</div>
					</template>
				</el-table-column>
				<el-table-column prop="IsEnable" label="状态" min-width="100">
					<template slot-scope="scope">
						<a-tag :color="scope.row.IsEnable?'blue':'red'">{{ scope.row.IsEnable?'有效':'失效' }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column label="操作" width="160" fixed="right">
					<template slot-scope="scope">
						<div class="tableleft">
							<oprateBtn title="修改" icon="icon-editor1" color="#1890FF" @tap="seeList(scope.row, 2)">
							</oprateBtn>
							<oprateBtn title="删除" icon="icon-delete" color="red" @tap="setList(scope.row,1)">
							</oprateBtn>
							<oprateBtn title="状态" icon="icon-shezhi" color="blue" @tap="setList(scope.row,2)">
							</oprateBtn>
							<oprateBtn title="申请项" icon="icon-xinjianzixiang" color="blue"
								@tap="$router.push(`PracticeSessionDeclare?ID=${scope.row.ID}`)"></oprateBtn>
							<oprateBtn title="主题" icon="icon-julebu1" color="green"
								@tap="$router.push(`PracticeSessionTheme?ID=${scope.row.ID}`)"></oprateBtn>
							<oprateBtn title="奖项" icon="icon-huodong" color="pink"
								@tap="$router.push(`PracticeSessionPrize?ID=${scope.row.ID}`)"></oprateBtn>
							<oprateBtn title="设置审批流程" icon="icon-guanli" color="blue" @tap="setListlc(scope.row)">
								</oprateBtn>
								
								
						</div>
					</template>
				</el-table-column>
			</el-table>
			<pagination @handleSizeChange="handleSizeChange" @handleCurrentChange="handleCurrentChange"
				:pagination="pagination"></pagination>
		</div>
		<add :text="text" v-show="addIf" @closeFun="closeFun"></add>
	</div>
</template>

<script>
	import add from './add';
	import pagination from '@components/pagination/index.vue';
	import moment from 'moment';
	import {
		ManagePracticeSessionDoGetPageList,
		ManagePracticeSessionDoDelete,
		ManagePracticeSessionDoSetEnable
	} from '@/api/follow';
	export default {
		props: {
			currentType: String
		},
		components: {
			add,
			pagination
		},
		data() {
			return {
				data: [],
				loading: false,
				form: this.$form.createForm(this, {
					name: 'advanced_search'
				}),
				pagination: this.global.pagination,
				addIf: false,
				text: {},
				values: {}
			};
		},
		created() {
			this.getList();
		},
		methods: {
			moment,
			handleSearch(e) {
				e.preventDefault();
				this.form.validateFields((error, values) => {
					this.pagination.currentPage = 1;
					this.values = {
						...this.values,
						...values
					};
					this.getList();
				});
			},
			handleReset() {
				this.form.resetFields();
				this.values = {};
				this.getList();
			},
			handleSizeChange(val) {
				this.pagination.pageSize = val;
				this.getList();
			},
			handleCurrentChange(val) {
				this.pagination.currentPage = val;
				this.getList();
			},
			async getList() {
				this.loading = true;
				let data = {};
				data = {
					...this.values,
					pageIndex: this.pagination.currentPage,
					pageSize: this.pagination.pageSize
				};
				let res = {};
				if (this.currentType == 'manager') {
					res = await ManagePracticeSessionDoGetPageList(data);
				}
				this.loading = false;
				this.data = res.data.data;
				const pagination = {
					...this.pagination
				};
				pagination.total = res.data.pageInfo.TotalItemCount;
				this.pagination = pagination;
			},
			seeList(text, type) {
				this.text = {
					...text,
					currentType: this.currentType,
					time: new Date()
				};
				this.addIf = !this.addIf;
			},
			setList(text, type) {
				let that = this;
				this.$confirm({
					title: '提示',
					content: type == 1 ? `您确定删除该数据吗？` : `您确定改变该数据的状态吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {};
						data.id = text.ID;
						let res = type == 1 ? await ManagePracticeSessionDoDelete(data) :
							await ManagePracticeSessionDoSetEnable(data);
						that.$message[res.data.code == 0 ? 'success' : 'error'](res.data.msg);
						if (res.data.code == 0) {
							that.getList();
						}
					}
				});
			},
			
			
			setListlc(text){
				this.$router.push({
					name: 'PracticeTeamFlow',
					query: {
						SessionID: text.ID,
						Name: text.Name,
					}
				});
			},
			closeFun(data) {
				this.addIf = false;
				if (data == 1) {
					this.getList();
				}
			}
		}
	};
</script>
